{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
{/block}
{block name="main"}
<div class="options-btn">
	<button class="btn-common-delete" onclick="batchDelete()">批量删除</button>
	<button class="btn-common" onclick="location.href='{:__URL('ADMIN_MAIN/config/addlink')}';">添加友情链接</button>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 2%">
		<col style="width: 30%;">
		<col style="width: 30%;">
		<col style="width: 12%;">
		<col style="width: 12%;">
		<col style="width: 4%;">
		<!-- <col style="width: 20%;"> -->
		<col style="width:10%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><i class="checkbox-common"><input type="checkbox" ></i></th>
			<th align="left">链接名称</th>
			<th align="left">链接地址</th>
			<th>是否打开新窗口</th>
			<th>是否显示</th>
			<th>排序</th>
			<!-- <th>图片</th> -->
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="linkList"></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
//分页数据
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/linklist')}",
		data : { "page_index" : page_index, "page_size" : $("#showNumber").val() },
		success : function(data) {
			console.log(data);
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					var link_id = data['data'][i]['link_id'];
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data['data'][i]['link_id']+'" ></i></td>';
					//html += '<td><input type="text" min="0" value="'+ data["data"][i]["link_sort"]+'"  nav_id="'+ data['data'][i]['link_id']+'" class="num" ></td>';
					
					html += '<td align="left" title="'+data["data"][i]["link_title"]+'">' + data["data"][i]["link_title"]+ '</td>';
					html += '<td align="left">' + data["data"][i]["link_url"]+ '</td>';
					if(data["data"][i]["is_blank"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class" onclick="modifyPlatformLinkListIsBlank(this,'+link_id+',0,'+data['data'][i]["is_blank"]+')"><img src="ADMIN_IMG/checked.png" alt="" width="15"/></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class" onclick="modifyPlatformLinkListIsBlank(this,'+link_id+',1,'+data['data'][i]["is_blank"]+')"><img src="ADMIN_IMG/un_checked.png" alt="" width="15"/></a></td>';
					}
					if(data["data"][i]["is_show"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class" onclick="modifyPlatformLinkListIsShow(this,'+link_id+',0,'+data['data'][i]["is_show"]+')"><img src="ADMIN_IMG/checked.png" alt="" width="15"/></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class" onclick="modifyPlatformLinkListIsShow(this,'+link_id+',1,'+data['data'][i]["is_show"]+')"><img src="ADMIN_IMG/un_checked.png" alt="" width="15"/></a></td>';
					}
					//html += '<td><input type="number" min="0" value="'+ data["data"][i]["link_sort"]+'" nav_id="'+ data['data'][i]['link_id']+'" class="num input-common input-common-sort" onchange="updateClass('+i+','+data["data"][i]["link_id"]+')" id="sort'+i+'"></td>';
					
					html += '<td>'+ data["data"][i]["link_sort"] +'</td>';
// 					if(data["data"][i]["link_pic"] != ''){
// 						html += '<td><image src=' + __IMG(data["data"][i]["link_pic"])+ ' style="width:100px;"></td>';
// 					}else{
// 						html += '<td></td>';
// 					}
					html += '<td><a href="'+__URL('ADMIN_MAIN/config/updatelink?link_id='+ data['data'][i]['link_id'])+'">修改</a><a style="cursor: pointer;" onclick="deleteLink('+data['data'][i]['link_id']+')">删除</a></td> ';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="8">暂无友情链接</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function batchDelete() {
	var link_id= [];
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			link_id.push($(this).val());
		}
	});
	if(link_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deleteLink(link_id);
}

function deleteLink(link_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
					$.ajax({
					type:"post",
					url:"{:__URL('ADMIN_MAIN/config/dellink')}",
					data:{ 'link_id':link_id.toString() },
					success:function (data) {
						if(data['code'] > 0){
							showTip(data['message'],'success');
							LoadingInfo(getCurrentIndex(link_id,'.table-class tbody'));
						}else{
							showTip(data['message'],'error');
						}
					}
				});
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			}
		},
		contentText:"确定删除？",
	});
}

function modifyPlatformLinkListIsBlank(eve,link_id,is_show,is_blank){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/System/modifyPlatformLinkListIsBlank')}",
		data : {
			"link_id" : link_id,
			"is_show" : is_show
		},
		success : function(data) {
			if(data["code"] > 0 ){
				if(is_show==1){
					showTip('启用成功','success');
					$(eve).addClass('active').attr('onclick','modifyPlatformLinkListIsBlank(this,'+link_id+',0,'+is_blank+')').html('<img src="ADMIN_IMG/checked.png" alt="" width="15"/>');
				}else{
					showTip('禁用成功','success');
					$(eve).removeClass('active').attr('onclick','modifyPlatformLinkListIsBlank(this,'+link_id+',1,'+is_blank+')').html('<img src="ADMIN_IMG/un_checked.png" alt="" width="15"/>');
				}
			}else{
				showTip(data["message"],'error');
			}
		}
	})
}

function modifyPlatformLinkListIsShow(eve,link_id,is_use,is_show){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/System/modifyPlatformLinkListIsShow')}",
		data : {
			"link_id" : link_id,
			"is_use" : is_use
		},
		success : function(data) {
			if(data["code"] > 0 ){
				if(is_use==1){
					showTip('启用成功','success');
					$(eve).addClass('active').attr('onclick','modifyPlatformLinkListIsShow(this,'+link_id+',0,'+is_show+')').html('<img src="ADMIN_IMG/checked.png" alt="" width="15"/>');
				}else{
					showTip('禁用成功','success');
					$(eve).removeClass('active').attr('onclick','modifyPlatformLinkListIsShow(this,'+link_id+',1,'+is_show+')').html('<img src="ADMIN_IMG/un_checked.png" alt="" width="15"/>');
				}
			}else{
				showTip(data["message"],'error');
			}
		}
	})
}
</script>
{/block}